var controller = {}

controller.getRecycle= function(req, res, next){
    res.render('recycle');
}

controller.getDeletePreview = function(req, res, next){
    console.log(req.query)
    var ql = 'select id, firstnav, secondnav, time, content,filename from content where tel = "' + req.query.tel + '" and id = "deFolder" and secondnav != "" or id ="deFile";';
    console.log(ql)
    conn.query(ql, function(err, results, fields){
        if(err) throw err;

        res.send({
            code: 200,
            recycleList: results
        })
    });
}

controller.revokeRecycle = function(req, res, next){
    if (req.query.id === 'deFile') {
    var ql = 'update content set id = "upload", time ="'+ req.query.time +'" where firstnav ="' + req.query.firstnav + '" and secondnav ="' + req.query.secondnav +'" and tel ="' + req.query.tel + '";';
    } else {
    var ql = 'update content set id = "revoke", time ="'+ req.query.time +'" where firstnav ="' + req.query.firstnav + '" and secondnav ="' + req.query.secondnav +'" and tel ="' + req.query.tel + '";';
    }
    console.log(ql)
    conn.query(ql, function(err, results, fields){
        if(err) throw err;
        res.send({
            code: 200
        })
    })

}

controller.deleteRecycle = function(req, res, next){
    var ql = 'delete from content where firstnav ="' + req.query.firstnav + '" and secondnav ="' + req.query.secondnav +'" and tel ="' + req.query.tel + '";';
    console.log(ql)
    conn.query(ql, function(err, results, fields){
        if(err) throw err;
        res.send({
            code: 200
        })
    })
}

module.exports = controller;